﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Com.Framework;
using Com.Framework.Data;
using Com.Library.DB.User;

namespace Com.Web.coffinegurunaru.popup
{
	public partial class pop_pwsearch : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (this.IsPostBack)
			{
				string UserName = Request.Form["UserName"].Parse(string.Empty);
				string UserID = Request.Form["UserID"].Parse(string.Empty);
				string Email = Request.Form["Email"].Parse(string.Empty);

				if (UserName == string.Empty)
				{
					ClientScript.RegisterClientScriptBlock(this.GetType(), "loginerror", @"
<script language='javascript'>
alert('이름을 입력하세요.');
location.href='/popup/pop_pwsearch.aspx';
</script>
");
					return;
				}
				if (UserID == string.Empty)
				{
					ClientScript.RegisterClientScriptBlock(this.GetType(), "loginerror", @"
<script language='javascript'>
alert('아이디를 입력하세요.');
location.href='/popup/pop_pwsearch.aspx';
</script>
");
					return;
				}
				if (Email == string.Empty)
				{
					ClientScript.RegisterClientScriptBlock(this.GetType(), "loginerror", @"
<script language='javascript'>
alert('이메일을 입력하세요.');
location.href='/popup/pop_pwsearch.aspx';
</script>
");
					return;
				}

				ListData<UserEntity, OutputEntity> result = UserModel.GetList(0, 1, 20, null, UserID, null, null, null, null);

				if (result.Record.Count == 0)
				{
					ClientScript.RegisterClientScriptBlock(this.GetType(), "loginerror", @"
<script language='javascript'>
alert('유저가 존재하지 않습니다.');
location.href='/popup/pop_pwsearch.aspx';
</script>
");
				}

				foreach (UserEntity item in result.Record)
				{
					if (item.Email.ToLower() == Email.ToLower() && item.UserName == UserName)
					{
						ClientScript.RegisterClientScriptBlock(this.GetType(), "loginerror", @"
<script language='javascript'>
alert('새로운 비밀번호를 이메일로 발송하였습니다.');
self.close();
</script>
");
						return;
					}
				}

				ClientScript.RegisterClientScriptBlock(this.GetType(), "loginerror", @"
<script language='javascript'>
alert('입력한 정보가 맞지 않습니다.');
location.href='/popup/pop_pwsearch.aspx';
</script>
");
			}
		}
	}
}
